package com.medical.literature.search.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.medical.literature.search.entity.SearchHistory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 搜索历史Mapper接口
 */
@Mapper
public interface SearchHistoryMapper extends BaseMapper<SearchHistory> {
    
    /**
     * 查询用户最近的搜索历史
     */
    @Select("SELECT keyword FROM search_history WHERE user_id = #{userId} ORDER BY search_time DESC LIMIT #{limit}")
    List<String> selectRecentSearchHistory(@Param("userId") Long userId, @Param("limit") int limit);
    
    /**
     * 删除用户的搜索历史
     */
    @Select("DELETE FROM search_history WHERE user_id = #{userId}")
    void deleteByUserId(@Param("userId") Long userId);
    
    /**
     * 查询热门搜索关键词
     */
    @Select("SELECT keyword FROM search_history GROUP BY keyword ORDER BY COUNT(*) DESC LIMIT #{limit}")
    List<String> selectHotKeywords(@Param("limit") int limit);
}